package com.your.company.demo.bootstrap.v1_0_0.activator;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.alibaba.druid.pool.DruidDataSource;
import com.strato.base.env.v1_0_0.GlobalEnvironment;
import com.strato.base.osgi.v1_0_0.BundleUtil;
import com.strato.jdbc.datasource.v1_0_0.DataSourceFactory;
import com.strato.transaction.v1_0_0.api.jdbc.DataSourceTransactionManager;
import com.strato.transaction.v1_0_0.mvc.TransactionInterceptor;

public class Activator implements BundleActivator {

	@Override
	public void start(BundleContext bundleContext) throws Exception {
		DruidDataSource datasource=new DruidDataSource();
		datasource.setUrl(GlobalEnvironment.getInstance().resolveString("${demo.datasource.commmon.url}"));
		datasource.setUsername(GlobalEnvironment.getInstance().resolveString("${demo.datasource.common.username}"));
		datasource.setPassword(GlobalEnvironment.getInstance().resolveString("${demo.datasource.common.password}"));
		datasource.setInitialSize(0);
		datasource.setMaxActive(GlobalEnvironment.getInstance().resolveInteger("${demo.datasource.common.maxActive}"));
		DataSourceFactory.getInstance().setDataSource("common", datasource);
		TransactionInterceptor txInterceptor=new TransactionInterceptor();
		DataSourceTransactionManager txManager=new DataSourceTransactionManager();
		txInterceptor.setTransactionManager(txManager);
		BundleUtil.exportServices(bundleContext, txInterceptor, null, null);
		BundleUtil.exportServices(bundleContext, txManager, null, null);
	}

	@Override
	public void stop(BundleContext arg0) throws Exception {
	}

}
